package test;

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.InputMismatchException;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cesdentalrecord.dao.view.AddStudentView;

public class ActionContainer {

	public void addAction(ActionEvent event,JPanel nullPanel,JTextField surnameTextField,JTextField firstNameTextField,JTextField midNameTextField,JTextField ageTextField,JComboBox sexComboBox,
			JTextField placeOfBirth,JTextField address,JTextField parent,JTextField occupation, JTextField medicalHistory,JComboBox grade,JComboBox section,JComboBox monthOfBirth,JComboBox dayOfBirth,JTextField yearOfBirth){
		String surname = surnameTextField.getText();
    	String firstname = firstNameTextField.getText();
        String mi = midNameTextField.getText();
        String date = (String)monthOfBirth.getSelectedItem();               
        String age = ageTextField.getText();
        String sex = (String) sexComboBox.getSelectedItem();
        String bplace = placeOfBirth.getText();
        String addresss = address.getText(); 
        String parents = parent.getText();
        String occu = occupation.getText();
        String medhist = medicalHistory.getText();
        String grades = (String)grade.getSelectedItem();
        String sections = (String)section.getSelectedItem();
        String month = (String)monthOfBirth.getSelectedItem();
        String day = (String)dayOfBirth.getSelectedItem();
        String year = yearOfBirth.getText();
        
        AddStudentView asv = new AddStudentView();
        // surname.getText();
         try {
        	 if(	 (surname.length()>0)&&
        			 (firstname.length()>0)&&
        			 (mi.length()>0)&&
        			 (date.length()>0)&&
        			 (age.length()>0)&&
        			 (sex.length()>0)&&
        			 (bplace.length()>0)&&
        			 (addresss.length()>0)&&
        			 (parents.length()>0)&&
        			 (occu.length()>0)&&
        			 (grades.length()>0)&&
        			 (sections.length()>0)&&
        			 (month.length()>0)&&
        			 (day.length()>0)&&
        			 (year.length()>0)&&
        			 (grades.length()>0)){
        		 try{
        			int  myage = Integer.parseInt(age);
			asv.sendAddStudentRequest(surname,firstname,mi,sex,grades,sections,month,day,year,
					bplace,addresss,parents,occu,medhist,myage);
			surnameTextField.setText("");
		     firstNameTextField.setText("");
		     midNameTextField.setText("");
		     monthOfBirth.setSelectedItem("");               
		     ageTextField.setText("");
		     sexComboBox.setSelectedItem("");
		     placeOfBirth.setText("");
		     address.setText(""); 
		     parent.setText("");
		     occupation.setText("");
		     medicalHistory.setText("");
		     grade.setSelectedItem("");
		     section.setSelectedItem("");
		     monthOfBirth.setSelectedItem("");
		     dayOfBirth.setSelectedItem("");
		     yearOfBirth.setText("");
		     JOptionPane.showMessageDialog( nullPanel, "Add New Student Record Successful ","SUCCESS", 1);
        		 }
        		 catch(InputMismatchException m){
        			 JOptionPane.showMessageDialog( nullPanel, "Enter am integer for age","Error", 0);
        		 }
        		 }
        	 else {
        		 JOptionPane.showMessageDialog( nullPanel, "Missing Some Inputs","Add New Student Record Failed", 0);
        	 }
    	} catch (Exception e1) {
			// TODO Auto-generated catch block
    		JOptionPane.showMessageDialog( nullPanel, "Missing Some Inputs","Add New Student Record Failed", 0);
    	
    		e1.printStackTrace();
		}
	}
	
	public void addReset(ActionEvent event, int mode,JTextField surnameTextField,JTextField firstNameTextField,JTextField midNameTextField,JTextField ageTextField,JComboBox sexComboBox,
			JTextField placeOfBirth,JTextField address,JTextField parent,JTextField occupation, JTextField medicalHistory,JComboBox grade,JComboBox section,JComboBox monthOfBirth,JComboBox dayOfBirth,JTextField yearOfBirth){
	
		 try {
			 surnameTextField.setText("");
		     firstNameTextField.setText("");
		     midNameTextField.setText("");
		     monthOfBirth.setSelectedItem("");               
		     ageTextField.setText("");
		     sexComboBox.setSelectedItem("");
		     placeOfBirth.setText("");
		     address.setText(""); 
		     parent.setText("");
		     occupation.setText("");
		     medicalHistory.setText("");
		     grade.setSelectedItem("");
		     section.setSelectedItem("");
		     monthOfBirth.setSelectedItem("");
		     dayOfBirth.setSelectedItem("");
		     yearOfBirth.setText("");
			 
		 }
		 
         catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	
	
	
}
